package com.objecteffects.ilmp.tumblr.method;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * @author Rusty Wright
 */
// @JsonInclude(JsonInclude.Include.ALWAYS)
// @JsonPropertyOrder({
// "meta", "response"
// })
abstract class BaseResponse<T> {
    private final Meta meta;
    private final T response;

    // @JsonIgnore
    private final Map<String, Object> additionalProperties = new HashMap<>();

    @JsonCreator
    public BaseResponse(@JsonProperty("meta")
    final Meta _meta, @JsonProperty("response")
    final T _response) {
        this.meta = Objects.requireNonNull(_meta);
        this.response = Objects.requireNonNull(_response);
    }

    @JsonProperty("meta")
    public Meta getMeta() {
        return this.meta;
    }

    @JsonProperty("response")
    public T getResponse() {
        return this.response;
    }

    @JsonAnyGetter
    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    @JsonAnySetter
    public void setAdditionalProperty(final String name, final Object value) {
        this.additionalProperties.put(name, value);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public boolean equals(final Object other) {
        return EqualsBuilder.reflectionEquals(this, other);
    }
}
